From 001175d831236c353c87e0bf603ec26809c35755 Mon Sep 17 00:00:00 2001 From: robertl Date: Sat, 24 Jul 2004 19:51:21 +0000 Subject: [PATCH] Implement '-vs' status display for Garmin and Magellan on waypoint download from the unit. --- garmin.c | 17 ++++++++++++++--- jeeps/gpsapp.c | 7 +++++-- jeeps/gpsapp.h | 2 +- jeeps/gpscom.c | 4 ++-- jeeps/gpscom.h | 2 +- magproto.c | 6 +++++- waypt.c | 10 ++++++++-- 7 files changed, 36 insertions(+), 12 deletions(-) diff --git a/garmin.c b/garmin.c index 075c8e9a2..d3cd6cd3d 100644 --- a/garmin.c +++ b/garmin.c @@ -148,6 +148,17 @@ rw_deinit(void) } } +static int +waypt_read_cb(int total_ct, GPS_PWay *way) +{ + static int i; + + if (global_opts.verbose_status) { + i++; + waypt_status_disp(total_ct, i); + } +} + static void waypt_read(void) { @@ -163,7 +174,7 @@ waypt_read(void) return; } - if ((n = GPS_Command_Get_Waypoint(portname, &way)) < 0) { + if ((n = GPS_Command_Get_Waypoint(portname, &way, waypt_read_cb)) < 0) { fatal(MYNAME ":Can't get waypoint from %s\n", portname); } @@ -371,6 +382,7 @@ sane_GPS_Way_New(void) return way; } + static int waypt_write_cb(GPS_PWay *way) { @@ -379,8 +391,7 @@ waypt_write_cb(GPS_PWay *way) if (global_opts.verbose_status) { i++; - fprintf(stdout, "%d/%d/%d\r", i*100/n, i, n); - fflush(stdout); + waypt_status_disp(n, i); } return 0; } diff --git a/jeeps/gpsapp.c b/jeeps/gpsapp.c index 6c30003ea..5f8617a93 100644 --- a/jeeps/gpsapp.c +++ b/jeeps/gpsapp.c @@ -574,7 +574,7 @@ static void GPS_A001(GPS_PPacket packet) ** ** @return [int32] number of waypoint entries ************************************************************************/ -int32 GPS_A100_Get(const char *port, GPS_PWay **way) +int32 GPS_A100_Get(const char *port, GPS_PWay **way, int (*cb)()) { static UC data[2]; int32 fd; @@ -628,7 +628,6 @@ int32 GPS_A100_Get(const char *port, GPS_PWay **way) return gps_errno; if(!GPS_Send_Ack(fd, &tra, &rec)) return gps_errno; - switch(gps_waypt_type) { case pD100: @@ -680,6 +679,10 @@ int32 GPS_A100_Get(const char *port, GPS_PWay **way) GPS_Error("A100_GET: Unknown waypoint protocol"); return PROTOCOL_ERROR; } + /* Issue callback for status updates. */ + if (cb) { + cb(n, &((*way)[i])); + } } if(!GPS_Packet_Read(fd, &rec)) diff --git a/jeeps/gpsapp.h b/jeeps/gpsapp.h index 5f27450a3..1ceecaef5 100644 --- a/jeeps/gpsapp.h +++ b/jeeps/gpsapp.h @@ -11,7 +11,7 @@ extern "C" int32 GPS_Init(const char *port); -int32 GPS_A100_Get(const char *port, GPS_PWay **way); +int32 GPS_A100_Get(const char *port, GPS_PWay **way, int (*cb)(int ct, GPS_PWay *)); int32 GPS_A100_Send(const char *port, GPS_PWay *way, int32 n, int (*cb)(GPS_PWay *)); int32 GPS_A200_Get(const char *port, GPS_PWay **way); diff --git a/jeeps/gpscom.c b/jeeps/gpscom.c index 235a5c4ea..1e45be28e 100644 --- a/jeeps/gpscom.c +++ b/jeeps/gpscom.c @@ -82,14 +82,14 @@ int32 GPS_Command_Off(const char *port) ** @return [int32] number of waypoint entries ************************************************************************/ -int32 GPS_Command_Get_Waypoint(const char *port, GPS_PWay **way) +int32 GPS_Command_Get_Waypoint(const char *port, GPS_PWay **way, int (*cb)()) { int32 ret=0; switch(gps_waypt_transfer) { case pA100: - ret = GPS_A100_Get(port,way); + ret = GPS_A100_Get(port,way, cb); break; default: GPS_Error("Get_Waypoint: Unknown waypoint protocol"); diff --git a/jeeps/gpscom.h b/jeeps/gpscom.h index 90c0cba52..0d8415736 100644 --- a/jeeps/gpscom.h +++ b/jeeps/gpscom.h @@ -28,7 +28,7 @@ int32 GPS_Command_Send_Almanac(const char *port, GPS_PAlmanac *alm, int32 n); int32 GPS_Command_Get_Track(const char *port, GPS_PTrack **trk); int32 GPS_Command_Send_Track(const char *port, GPS_PTrack *trk, int32 n); -int32 GPS_Command_Get_Waypoint(const char *port, GPS_PWay **way); +int32 GPS_Command_Get_Waypoint(const char *port, GPS_PWay **way,int (*cb)()); int32 GPS_Command_Send_Waypoint(const char *port, GPS_PWay *way, int32 n, int (*cb)()); int32 GPS_Command_Get_Proximity(const char *port, GPS_PWay **way); diff --git a/magproto.c b/magproto.c index 829fc104d..646ee8d26 100644 --- a/magproto.c +++ b/magproto.c @@ -1,7 +1,7 @@ /* Communicate Thales/Magellan serial protocol. - Copyright (C) 2002 Robert Lipe, robertlipe@usa.net + Copyright (C) 2002, 2003, 2004 Robert Lipe, robertlipe@usa.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,6 +40,7 @@ static char *deficon; static char *bs; static char *noack; static int route_out_count; +static int waypoint_read_count; typedef enum { mrs_handoff = 0, @@ -430,6 +431,8 @@ retry: } if (strncmp(ibuf, "$PMGNWPT,", 7) == 0) { waypoint *wpt = mag_wptparse(ibuf); + waypoint_read_count++; + waypt_status_disp(waypoint_read_count, waypoint_read_count); switch (global_opts.objective) { case wptdata: @@ -715,6 +718,7 @@ static void mag_rd_init(const char *portname) { time_t now, later; + waypoint_read_count = 0; if (bs) { bitrate=atoi(bs); diff --git a/waypt.c b/waypt.c index 7b6c7efd5..f5f2323a8 100644 --- a/waypt.c +++ b/waypt.c @@ -146,6 +146,13 @@ waypt_disp(const waypoint *wpt) printf("\n"); } +void +waypt_status_disp(int total_ct, int myct) +{ + fprintf(stdout, "%d/%d/%d\r", myct*100/total_ct, myct, total_ct); + fflush(stdout); +} + void waypt_disp_all(waypt_cb cb) { @@ -157,8 +164,7 @@ waypt_disp_all(waypt_cb cb) waypointp = (waypoint *) elem; if (global_opts.verbose_status) { i++; - fprintf(stdout, "%d/%d/%d\r", i*100/waypt_ct, i, waypt_ct); - fflush(stdout); + waypt_status_disp(waypt_ct, i); } (*cb) (waypointp); } -- 2.30.2